Skip to content

Instantly share code, notes, and snippets.

@nathantsoi
Last active January 19, 2024 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathantsoi/e892965b2d97f735a51b707d4a3b1eff to your computer and use it in GitHub Desktop.
Save nathantsoi/e892965b2d97f735a51b707d4a3b1eff to your computer and use it in GitHub Desktop.
linuxcnc install

Install LinuxCNC 2.9 with RTAI Kernel

LinuxCNC 2.9 runs with relative high max jitter on the preempt-rt kernel (100k+ ns Max Jitter). On the RTAI Kernel I'm getting ~10k Max Jitter.

Starting with the Debian 12 installer disk

I tried to install Debian 12 from the normal installer disk and then install linuxcnc, but this resulted in a segfault when running linuxcnc, but haltest and latency-test worked fine... idk why.

Then follow the linuxcnc install instructions.

wget https://www.linuxcnc.org/linuxcnc-install.sh
sudo bash linuxcnc-install.sh

I commented out the deb-src line in /etc/apt/sources.list.d/linuxcnc.list after installation and removed 2.9-uspace from the deb line.

Remove preempt-rt related packages:

sudo apt purge -y 'linux-image-rt-*' \
                  'linuxcnc-uspace*' \
                  linuxcnc-doc-en \
                  linux-headers-rt-amd64 \
                  linux-libc-dev

Finally, install the RTAI Kernel and linuxcnc packages:

# Install the RTAI kernel
sudo apt install -y linux-image-5.4.258-rtai-amd64 \
                    linux-headers-5.4.258-rtai-amd64 \
                    rtai-modules-5.4.258 \
                    linux-libc-dev=5.4.258-rtai-amd64-2
# Check the libc version matches (5.4.258)
apt policy linux-libc-dev
# Install linuxcnc (RTAI)
sudo apt install -y --no-install-recommends linuxcnc

Install the QTVCP dependencies:

/usr/lib/python3/dist-packages/qtvcp/designer/install_script

And test to make sure QTVCP is working:

qtvcp -d test_panel

Install starting with LinuxCNC 2.9 ISO

Remove raspi-firmware and preempt-rt related packages:

sudo dpkg --purge raspi-firmware
sudo apt purge -y 'linux-image-rt-*' \
                  'linuxcnc*' \
                  'linuxcnc-doc-*' \
                  linux-libc-dev

Finally, install the RTAI Kernel and linuxcnc packages:

Option 1 5.4 kernel:

# Install the RTAI kernel
sudo apt install -y linux-image-5.4.258-rtai-amd64 \
                    linux-headers-5.4.258-rtai-amd64 \
                    rtai-modules-5.4.258 \
                    linux-libc-dev=5.4.258-rtai-amd64-2
# Check the libc version matches (5.4.258)
apt policy linux-libc-dev

Option 2 4.19 kernel (must build linuxcnc from source to use this):

NOTE: Don't install from debs, install from source below.

# DEPRECATED
#export RTAI_VERSION=4.9.294
#cd ~/Downloads
#mkdir rtai-${RTAI_VERSION}
#cd rtai-${RTAI_VERSION}
## download the kernel
#wget https://github.com/NTULINUX/RTAI/releases/download/v5.3.3-gnu11/linux-headers-4.19.294-rtai-amd64_4.19.294-rtai-amd64-1_amd64.deb
#wget https://github.com/NTULINUX/RTAI/releases/download/v5.3.3-gnu11/linux-image-4.19.294-rtai-amd64_4.19.294-rtai-amd64-1_amd64.deb
#wget https://github.com/NTULINUX/RTAI/releases/download/v5.3.3-gnu11/linux-libc-dev_4.19.294-rtai-amd64-1_amd64.deb
#wget https://github.com/NTULINUX/RTAI/releases/download/v5.3.3-gnu11/rtai-modules-4.19.294_5.3.3-linuxcnc-delta_amd64.deb
## install
#sudo dpkg -i *.deb

(if not installing from source) Switch to the RT sources and install linuxcnc:

# comment out the uspace sources
sed -i '1,2 s/^/#/' /etc/apt/sources.list.d/linuxcnc-uspace.list
# use the rt sources
echo 'deb [arch=amd64,arm64 signed-by=/etc/apt/trusted.gpg.d/linuxcnc.gpg.key.binary.gpg] https://www.linuxcnc.org/ bookworm base 2.9-rt' > /etc/apt/sources.list.d/linuxcnc.list
# clear apt cache and update
sudo apt-get clean && sudo apt update
# Install linuxcnc (RTAI)
sudo apt install -y --no-install-recommends linuxcnc

Freeze the header and libc versions we installed:

sudo apt-mark hold linux-headers-amd64
sudo apt-mark hold linux-libc-dev

To boot the RTAI kernel, set grub to save the last booted kernel by editing /etc/default/grub:

GRUB_DEFAULT=saved
GRUB_SAVEDEFAULT=true

Run sudo update-grub then reboot and select the RTAI kernel from the advanced grub menu on the next boot.

Switch to xfce and lightdm (LinuxCNC does not run on gnome it seems):

sudo apt install -y xfce4 xfce4-session xfce4-goodies lightdm
sudo dpkg-reconfigure lightdm

Install TurboVNC (in a root shell):


wget -q -O- https://packagecloud.io/dcommander/turbovnc/gpgkey | \
  gpg --dearmor >/etc/apt/trusted.gpg.d/TurboVNC.gpg
pushd /etc/apt/sources.list.d
wget https://raw.githubusercontent.com/TurboVNC/repo/main/TurboVNC.list
popd
sudo apt update
sudo apt install -y turbovnc

Switch to xfce:

# switch to xfce
echo '$wm = "xfce";' > ~/.vnc/turbovncserver.conf

Run the server:

# add the path to the bash profile
echo 'export PATH=/opt/TurboVNC/bin:${PATH}' > ~/.bashrc
# open a new shell
# run server
vncserver

Build from Source (with RTAI Kernel)

Follow this guide: https://github.com/NTULINUX/RTAI/blob/master/README.INSTALL and https://linuxcnc.org/docs/html/code/building-linuxcnc.html:

Remove all other sources:

sudo apt-mark unhold linux-libc-dev linux-headers-amd64
sudo dpkg --purge raspi-firmware
sudo apt purge -y 'linux-image-rt-*' \
                  'linuxcnc*' \
                  'linuxcnc-doc-*' \
                  linux-libc-dev
sudo apt install -y git 

Install RTAI Kernel First

Install dependencies:

sudo apt install -y libc6-dev \
                    bison \
                    flex \
                    libncurses-dev

Get the RTAI Source:

# clone RTAI
cd ~/src/
git clone https://github.com/NTULINUX/RTAI.git
# checkout the code to match kernel version 4.19.265 (in the RTAI docs)
git checkout v5.3.3-delta

Then get the linux kernel source and patch it in a root shell:

cd /usr/src
sudo wget https://www.kernel.org/pub/linux/kernel/v4.x/linux-4.19.265.tar.xz
sudo tar xf linux-4.19.265.tar.xz
sudo ln -sfv linux-4.19.265 linux
cd linux
for i in "/home/cnc/src/RTAI/ksrc/v4.19.265/"*.patch ; do patch -p1 < "${i}" ; done
make olddefconfig
make menuconfig

I changed the following config options:

  • "Kernel hacking" -> "Compile-time checks and compiler options" -> "Strip assembler-generated symbols during link". -> False

Then build:

make bzImage && make modules
make install && make modules_install

Note: to re-build with changes, first run make clean then the make commands above again.

Then install LinuxCNC

Clone the source:

cd ~/src/
# clone
git clone https://github.com/LinuxCNC/linuxcnc.git linuxcnc-dev
cd linuxcnc-dev
# checkout tag version:
git checkout v2.9.2
# install dependencies
./debian/configure
sudo apt-get -y build-dep .
# check deps
sudo apt-get install -y dpkg-dev
dpkg-checkbuilddeps

Lock memory (in a root shell):

echo '* - memlock 20480' > /etc/security/limits.d/linuxcnc.conf

Configure:

cd ~/src/linuxcnc-dev/src
./autogen.sh
# a specific kernel
./configure --with-realtime=/usr/realtime-5.4.258-rtai-amd64/
# make
make
sudo make setuid

Run linuxcnc:

cd ~/src/linuxcnc-dev
# setup environment
. scripts/rip-environment
linuxcnc

Debugging

Tail debug logs (syslog):

sudo journalctl -kf

View logs from last boot:

SYSTEMD_COLORS=1 journalctl -b -1 -k | less +G -r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment